// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

// ************************************************************************* //
//                                VisWinTriad.C                              //
// ************************************************************************* //

#include <vtkTriad2D.h>
#include <vtkProperty2D.h>
#include <vtkRenderer.h>

#include <VisWindow.h>
#include <VisWindowColleagueProxy.h>
#include <VisWinTriad.h>


// ****************************************************************************
//  Method: VisWinTriad constructor
//
//  Arguments:
//      p      A proxy that allows more access to the VisWindow for this 
//             colleague.
//
//  Programmer: Hank Childs
//  Creation:   June 8, 2000
//
//  Modifications:
//
//    Hank Childs, Thu Jul  6 11:01:24 PDT 2000
//    Initialized data member addedTriad.
//
//    Hank Childs, Mon Jul 10 16:58:06 PDT 2000
//    Removed axis actors in favor of vtkTriad2D class.
//
//    Kathleen Bonnell, Mon Nov 26 9:16:32 PST 2001
//    Make the triad un-pickable.
//
// ****************************************************************************

VisWinTriad::VisWinTriad(VisWindowColleagueProxy &p) : VisWinColleague(p)
{
    triad = vtkTriad2D::New();
    triad->PickableOff();
    addedTriad = false;
}


// ****************************************************************************
//  Method: VisWinTriad destructor
//
//  Programmer: Hank Childs
//  Creation:   June 8, 2000
//
//  Modifications:
//
//    Hank Childs, Mon Jul 10 16:58:06 PDT 2000
//    Removed deletion of former data members for axes; added deletion of 
//    triad.
//
// ****************************************************************************

VisWinTriad::~VisWinTriad()
{
    if (triad != NULL)
    {
        triad->Delete();
        triad = NULL;
    }
}


// ****************************************************************************
//  Method: VisWinTriad::SetForegroundColor
//
//  Purpose:
//      Sets the color of the triad.
//
//  Arguments:
//      fr        The red component of the foreground color.
//      fg        The green component of the foreground color.
//      fb        The blue component of the foreground color.
//
//  Programmer: Hank Childs
//  Creation:   June 8, 2000
//
//  Modifications:
//
//    Hank Childs, Mon Jul 10 16:58:06 PDT 2000
//    Changed colors of triad's axes instead of former data members.
//
// ****************************************************************************

void
VisWinTriad::SetForegroundColor(double fr, double fg, double fb)
{
    triad->GetXAxis()->GetProperty()->SetColor(fr, fg, fb);
    triad->GetYAxis()->GetProperty()->SetColor(fr, fg, fb);
    triad->GetZAxis()->GetProperty()->SetColor(fr, fg, fb);
}


// ****************************************************************************
//  Method: VisWinTriad::SetLineWidth
//
//  Purpose:
//      Sets the line width of the triad.
//
//  Arguments:
//      xw        Sets the line width of the x axis.
//      yw        Sets the line width of the y axis.
//      zw        Sets the line width of the z axis.
//
//  Programmer: Alister Maguire
//  Creation:   Wed Feb 28 09:59:18 PST 2018
//
//  Modifications:
//
// ****************************************************************************

void
VisWinTriad::SetLineWidth(float xw, float yw, float zw)
{
    triad->GetXAxis()->GetProperty()->SetLineWidth(xw);
    triad->GetYAxis()->GetProperty()->SetLineWidth(yw);
    triad->GetZAxis()->GetProperty()->SetLineWidth(zw);
}


// ****************************************************************************
//  Method: VisWinTriad::SetFontFamily
//
//  Purpose:
//      Sets the font family for the x,y,z triad labels. 
//
//  Arguments:
//      font        the chosen font. 
//
//  Programmer: Alister Maguire
//  Creation:   Wed Feb 28 09:59:18 PST 2018
//
//  Modifications:
//
//      Alister Maguire, Fri Mar  9 11:10:43 PST 2018
//      Changed method of setting to switch statement in case
//      mapping is changed. 
//
// ****************************************************************************

void
VisWinTriad::SetFontFamily(int font)
{
    switch (font)
    {
        case 0:
            triad->GetXAxis()->SetFontFamilyToArial();
            triad->GetYAxis()->SetFontFamilyToArial();
            triad->GetZAxis()->SetFontFamilyToArial();
            break;
        case 1:
            triad->GetXAxis()->SetFontFamilyToCourier();
            triad->GetYAxis()->SetFontFamilyToCourier();
            triad->GetZAxis()->SetFontFamilyToCourier();
            break;
        case 2:
            triad->GetXAxis()->SetFontFamilyToTimes();
            triad->GetYAxis()->SetFontFamilyToTimes();
            triad->GetZAxis()->SetFontFamilyToTimes();
            break;

    }
}


// ****************************************************************************
//  Method: VisWinTriad::SetBold
//
//  Purpose:
//      Sets the bold option for the x,y,z triad labels. 
//
//  Arguments:
//      bold        whether or not to use bold. 
//
//  Programmer: Alister Maguire
//  Creation:   Wed Feb 28 09:59:18 PST 2018
//
//  Modifications:
//
// ****************************************************************************

void
VisWinTriad::SetBold(bool bold)
{
    triad->GetXAxis()->SetBold(bold);
    triad->GetYAxis()->SetBold(bold);
    triad->GetZAxis()->SetBold(bold);
}


// ****************************************************************************
//  Method: VisWinTriad::SetItalic
//
//  Purpose:
//      Sets the italic option for the x,y,z triad labels. 
//
//  Arguments:
//      italic        whether or not to use italic. 
//
//  Programmer: Alister Maguire
//  Creation:   Wed Feb 28 09:59:18 PST 2018
//
//  Modifications:
//
// ****************************************************************************

void
VisWinTriad::SetItalic(bool italic)
{
    triad->GetXAxis()->SetItalic(italic);
    triad->GetYAxis()->SetItalic(italic);
    triad->GetZAxis()->SetItalic(italic);
}


// ****************************************************************************
//  Method: VisWinTriad::Start3DMode
//
//  Purpose:
//      We are about to enter 3D mode, so the triad should be added to the
//      background, as long as there are plots.
//
//  Programmer: Hank Childs
//  Creation:   June 8, 2000
//
//  Modifications:
//
//    Hank Childs, Thu Jul  6 11:01:24 PDT 2000
//    Pushed logic for adding the triad into its own routine.
//
// ****************************************************************************

void
VisWinTriad::Start3DMode(void)
{
    if (ShouldAddTriad())
    {
        AddTriadToWindow();
    }
}


// ****************************************************************************
//  Method: VisWinTriad::Stop3DMode
//
//  Purpose:
//      We are about to leave 3D mode, so the triad should be removed from the
//      background.
//
//  Programmer: Hank Childs
//  Creation:   June 8, 2000
//
//  Modifications:
//
//    Hank Childs, Thu Jul  6 11:01:24 PDT 2000
//    Pushed logic for removing the triad into its own routine.
//
// ****************************************************************************

void
VisWinTriad::Stop3DMode(void)
{
    RemoveTriadFromWindow();
}


// ****************************************************************************
//  Method: VisWinTriad::HasPlots
//
//  Purpose:
//      This routine is how the vis window tells this colleague that it now
//      has plots.  We can now add the triad.
//
//  Programmer: Hank Childs
//  Creation:   July 6, 2000
//
// ****************************************************************************

void
VisWinTriad::HasPlots(void)
{
    if (ShouldAddTriad())
    {
        AddTriadToWindow();
    }
}


// ****************************************************************************
//  Method: VisWinTriad::NoPlots
//
//  Purpose:
//      This routine is how the vis window tells this colleague that it no
//      longer has plots.  Remove the triad.
//
//  Programmer: Hank Childs
//  Creation:   July 6, 2000
//
// ****************************************************************************

void
VisWinTriad::NoPlots(void)
{
    RemoveTriadFromWindow();
}


// ****************************************************************************
//  Method: VisWinTriad::ShouldAddTriad
//
//  Purpose:
//      There are two constraints on whether the triad should be added to the
//      VisWindow - whether we are in 3D mode and whether we have plots.  This
//      buffers the logic for that so the individual operations don't need to
//      know about each other.
//
//  Returns:    true if the triad should be added to the window, false 
//              otherwise.
//
//  Programmer: Hank Childs
//  Creation:   July 6, 2000
//
// ****************************************************************************

bool
VisWinTriad::ShouldAddTriad()
{
    return (mediator.GetMode() == WINMODE_3D && mediator.HasPlots());
}


// ****************************************************************************
//  Method: VisWinTriad::AddTriadToWindow
//
//  Purpose:
//      Adds the triad to the window.
//
//  Programmer: Hank Childs
//  Creation:   July 6, 2000
//
//  Modifications:
//
//    Hank Childs, Mon Jul 10 16:58:06 PDT 2000
//    Added triad to the background instead of former axes data members.
//    Registered the active camera with the triad.
//
//    Hank Childs, Fri Aug  4 14:44:32 PDT 2000
//    Put triad on foreground instead of background.
//
// ****************************************************************************

void
VisWinTriad::AddTriadToWindow(void)
{
    if (addedTriad)
    {
        return;
    }

    //
    // Get the camera of the canvas and register it with the triad.
    //
    vtkRenderer *canvas = mediator.GetCanvas();
    triad->SetCamera(canvas->GetActiveCamera());

    //
    // Add the triad to the background (note that we are using a different
    // renderer's camera -- the canvas').
    //
    vtkRenderer *foreground = mediator.GetForeground();
    foreground->AddActor2D(triad);

    addedTriad = true;
}


// ****************************************************************************
//  Method: VisWinTriad::RemoveTriadFromWindow
//
//  Purpose:
//      Removes the triad from the window.
//
//  Programmer: Hank Childs
//  Creation:   July 6, 2000
//
//  Modifications:
//
//    Hank Childs, Mon Jul 10 16:58:06 PDT 2000
//    Removed the triad from the background instead of former axes data
//    members.
//
//    Hank Childs, Fri Aug  4 14:44:32 PDT 2000
//    Put triad on foreground instead of background.
//
// ****************************************************************************

void
VisWinTriad::RemoveTriadFromWindow(void)
{
    if (! addedTriad)
    {
        return;
    }

    vtkRenderer *foreground = mediator.GetForeground();
    foreground->RemoveActor2D(triad);

    addedTriad = false;
}


// ****************************************************************************
//  Method: VisWinTriad::SetVisibility
//
//  Purpose:
//      Sets the visibility of the triad.
//
//  Programmer: Kathleen Bonnell 
//  Creation:   June 27, 2001 
//
// ****************************************************************************

void
VisWinTriad::SetVisibility(bool vis)
{
    triad->SetVisibility((int)vis);
}


